const firstUpperCase = function (str) {
  return str.replace(/\b(\w)(\w*)/g, function ($0, $1, $2) {
    return $1.toUpperCase() + $2.toLowerCase()
  })
}
const getBtn = (
  txt,
  funType,
  row,
  h,
  context,
  type = 'primary',
  parent,
  parentIndex
) => {
  return (
    <a
      href="javascript:;"
      class={`text-${type}`}
      onClick={() =>
        context[`on${firstUpperCase(funType)}`](row, parent, parentIndex)
      }
    >
      {txt}
    </a>
  )
}
// 产品类型
export const typeList = [
  {
    name: '兑换券',
    value: '1'
  },
  {
    name: '优惠券',
    value: '2'
  }
]

export const columns = ctx => {
  return [
    {
      prop: 'id',
      label: '方案ID'
    },
    {
      prop: 'name',
      label: '特殊节假日方案名称'
    },
    {
      prop: 'exchangeRangeName',
      label: '兑换范围'
    },
    {
      prop: 'productTypeName',
      label: '产品类型'
    },
    {
      prop: 'operator',
      label: '操作人'
    },
    {
      prop: 'updateTime',
      label: '修改时间'
    },
    {
      label: '操作',
      width: 200,
      render: (h, row, index) => {
        let btns = []
        // let edit = getBtn('编辑', 'edit', row, h, ctx)
        let detail = getBtn('详情', 'detail', row, h, ctx)
        let del = getBtn('删除', 'del', row, h, ctx)
        btns = [detail, del]
        return [
          <zm-button class="mr5" type="text" disabled={row.isEdit === '0'} onClick={() => ctx.onEdit(row)}>编辑</zm-button>,
          btns]
      }
    }
  ]
}
